﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using ESF.General;

#endregion


namespace ESF.DMS.FileSynchronizator.Config
{
	public class SynchronizedDirectoryElement : ConfigurationElement
	{
		[ConfigurationProperty("name", IsRequired = true)]
		public string name
		{
			get
			{
				return this["name"] as string;
			}
			set
			{
				this["name"] = value;
			}
		}


		[ConfigurationProperty("sourceDirectoryPath", IsRequired = true)]
		public string sourceDirectoryPath
		{
			get
			{
				return FileHelper.AddFinalSeparator (this["sourceDirectoryPath"] as string);
			}
			set
			{
				this["sourceDirectoryPath"] = value;
			}
		}


		[ConfigurationProperty("destinationDirectoryPath", IsRequired = true)]
		public string destinationDirectoryPath
		{
			get
			{
				return FileHelper.AddFinalSeparator (this["destinationDirectoryPath"] as string);
			}
			set
			{
				this["destinationDirectoryPath"] = value;
			}
		}


		[ConfigurationProperty("fileExtensions", IsRequired = false)]
		public string fileExtensions
		{
			get
			{
				return this["fileExtensions"] as string;
			}
			set
			{
				this["fileExtensions"] = value;
			}
		}


		public string [] fileExtensionsValue
		{
			get
			{
				return TextHelper.Split (',', fileExtensions).ToArray ();
			}
		}


		[ConfigurationProperty("userName", IsRequired = false)]
		public string userName
		{
			get
			{
				return this["userName"] as string;
			}
			set
			{
				this["userName"] = value;
			}
		}


		[ConfigurationProperty("userPassword", IsRequired = false)]
		public string userPassword
		{
			get
			{
				return this["userPassword"] as string;
			}
			set
			{
				this["userPassword"] = value;
			}
		}


		[ConfigurationProperty("userDomain", IsRequired = false)]
		public string userDomain
		{
			get
			{
				return this["userDomain"] as string;
			}
			set
			{
				this["userDomain"] = value;
			}
		}


		[ConfigurationProperty("startDateTimeFile", IsRequired = false)]
		public string startDateTimeFile
		{
			get
			{
				return this["startDateTimeFile"] as string;
			}
			set
			{
				this["startDateTimeFile"] = value;
			}
		}


		public DateTime? startDateTimeFileValue
		{
			get
			{
				return TextHelper.GetNullableDateTime (startDateTimeFile);
			}
		}


		[ConfigurationProperty("startDateFolder", IsRequired = false)]
		public string startDateFolder
		{
			get
			{
				return this["startDateFolder"] as string;
			}
			set
			{
				this["startDateFolder"] = value;
			}
		}


		public DateTime? startDateFolderValue
		{
			get
			{
				return TextHelper.GetNullableDateTime(startDateFolder, startDateFolderFormat);
			}
		}


		[ConfigurationProperty("startDateFolderFormat", IsRequired = false)]
		public string startDateFolderFormat
		{
			get
			{
				return (string.IsNullOrWhiteSpace (this["startDateFolderFormat"] as string) ? TextHelper.DEFAULT_DATE_FORMAT : this["startDateFolderFormat"] as string);
			}
			set
			{
				this["startDateFolderFormat"] = value;
			}
		}


		[ConfigurationProperty("startDateFolderDepth", IsRequired = false)]
		public int startDateFolderDepth
		{
			get
			{
				return (int) this["startDateFolderDepth"];
			}
			set
			{
				this["startDateFolderDepth"] = value;
			}
		}


		public bool DoImpersonateUser
		{
			get
			{
				return (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(userPassword));
			}
		}
	}
}
